package ge.modules.utils;

import ge.exceptions.FunctionNonSuported;
import ge.lowlevel.Interval;
import ge.lowlevel.UtilityEngine;
import ge.modules.Module;

 

public class DelayedActionModule extends Interval implements Module {

	private IAction action;
	
	private int time;
	private boolean loop;
	public DelayedActionModule(IAction action, int time, boolean loop)
	{
		this.action = action; 
		this.loop = loop;
		this.time = time;
	}
	
	public void activate()
	{
		try {
			UtilityEngine.get().setInterval(time, (Interval)this, loop);
		} catch (FunctionNonSuported e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	@Override
	public void run()
	{
		action.run();
	}
	@Override
	public void update() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void draw() {
		 
		
	}

	@Override
	/**
	 * 	Stops the interval
	 */
	public void delete() {
		
		//Si es null no se ha llegado a crear el temporizador
		if(getConcretTimer() == null)
			return;
		
		try {
			UtilityEngine.get().cancelInterval(this);
		} catch (FunctionNonSuported e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
